package com.qy139.store.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy139.entity.Picture;
import com.qy139.entity.Store;
import com.qy139.store.service.IStoreService;
import com.qy139.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhaochen
 * @since 2021-11-30
 */
@Api(tags = "共享自习室门店管理")
@RestController
@RequestMapping("/store")
public class StoreController {
    @Resource
    private IStoreService storeService;
    /*分页+模糊查询所有门店名字*/
    @ApiOperation(notes = "门店分页模糊查询", value = "分页查询门店")
    @GetMapping("/findAllStore")
    public Result findAllStore(Store store, Page page){
        QueryWrapper<Store> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("s_name",store.getSName());
        Page page1 = storeService.page(page, queryWrapper);
        return new Result(page1);
    }
    /*展示门店*/
    @ApiOperation(notes = "供自习室前端的下拉框使用", value = "查询门店")
    @GetMapping("/findAll")
    public Result findAll(){
        return new Result(storeService.list());
    }

    /*新增 修改 逻辑删除*/
    @ApiOperation(notes = "新增门店或修改门店", value = "新增、修改门店")
    @PutMapping("/updateStore")
    public Result updateStore(@RequestBody Store store){
        store.setUpdatetime(new Date());
        return new Result(storeService.saveOrUpdate(store));
    }
}

